<!doctype html>
<html>

<head>
	<meta charset="UTF-8">
	<title>修改项目经验</title>
	<meta name="viewport"
		content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css">
	<link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.min.css">
	<link rel="stylesheet" href="css/mui.min.css" />
	<!-- build:css css/app.css -->
	<link rel="stylesheet" href="css/base.css" />
	<link rel="stylesheet" href="css/common.css" />
	<!-- endbuild -->
</head>

<body>
	<header class="mui-bar mui-bar-nav">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		<h1 class="mui-title">修改项目经验</h1>
	</header>
	<div class="mui-content">
		<div class="resume-list">
			<div class="wrapper flex-row-center">
				<label>
					<span class="red">*</span>项目名称
				</label>
				<input id="project-name" type="text" placeholder="请填写" />
			</div>
		</div>
		<div class="resume-list">
			<div class="wrapper flex-row-center">
				<label><span class="red">*</span>开始时间</label>
				<input id="entry-time" type="text" placeholder="请选择" data-toggle='date' />
				<i class="mui-icon mui-icon-arrowright"></i>
			</div>
		</div>
		<div class="resume-list">
			<div class="wrapper flex-row-center">
				<label><span class="red">*</span>结束时间</label>
				<input id="overy-time" type="text" placeholder="请选择" data-toggle='date' />
				<i class="mui-icon mui-icon-arrowright"></i>
			</div>
		</div>
		<div class="resume-list">
			<div class="wrapper flex-row-center">
				<label>
					<span class="red">*</span>承担职位
				</label>
				<input id="position" type="text" placeholder="请填写" />
			</div>
		</div>
		<div class="resume-list">
			<div class="wrapper">
				<label>项目介绍</label>
			</div>
			<textarea id="projict-desc" placeholder="请填写"></textarea>
		</div>
		<button id="save" class="button button-blue">保存</button>
	</div>
	<script src="js/mui.min.js"></script>
	<script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
	<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/jquery-weui.min.js"></script>
	<!-- build:js js/app.js -->
	<script src="js/api.js"></script>
	<script src="js/tools.js"></script>
	<!-- endbuild -->
	<script>
		var href = window.location.href;
		var eid = 0;
		var data = {
			expId: null,
			projectName: '',
			beginTime: null,
			endTime: null,
			position: '',
			projectIntroduce: ''
		};
		if (href.indexOf('?') != -1) {
			eid = href.split('?')[1].split('=')[1];
		}
		function init(res) {
			if (res['projectName']) {
				data.projectName = res['projectName'];
				$('#project-name').val(res['projectName'])
			}
			if (res['beginTime']) {
				data.beginTime = res['beginTime'];
				$('#entry-time').val(res['beginTime'])
			}
			if (res['endTime']) {
				data.endTime = res['endTime'];
				$('#overy-time').val(res['endTime'])
			}
			if (res['position']) {
				data.position = res['position'];
				$('#position').val(res['position'])
			}
			if (res['projectIntroduce']) {
				data.projectIntroduce = res['projectIntroduce'];
				$('#projict-desc').val(res['projectIntroduce'])
			}
		}
		// 回显
		$.ajax({
			url: config.ME_API + 'h5/h5GetExperience',
			type: 'post',
			data: {
				expId: eid
			},
			success: function (res) {
				if (res.code == 2) {
					init(res.data.experience)
				} else {
					mui.toast(res.msg)
				}
			}
		})
		// 开始时间
		$("#entry-time").calendar({
			onChange: function (p, values, displayValues) {
				data.beginTime = values[0].replace(/\//g, '-')
			}
		});
		// 结束时间
		$("#overy-time").calendar({
			onChange: function (p, values, displayValues) {
				data.endTime = values[0].replace(/\//g, '-')
			}
		});
		// 保存
		$('#save').on('tap', function () {
			data.projectName = $('#project-name').val();
			data.position = $('#position').val();
			data.projectIntroduce = $('#projict-desc').val();
			data.expId = eid;
			console.log(data)
			if (data['projectName'] == '') {
				mui.toast('请填写项目名称!');
				return false
			}
			if (data['beginTime'] == null) {
				mui.toast('请选择开始时间!');
				return false
			}
			if (data['endTime'] == null) {
				mui.toast('请选择结束时间!');
				return false
			}
			if (data['position'] == '') {
				mui.toast('请填写承担职位!');
				return false
			}
			if (data['projectIntroduce'] == '') {
				mui.toast('请填写项目介绍!');
				return false
			}
			if (!isLogin()) {
				mui.toast('请先登录!');
				return false
			}
			$.ajax({
				url: config.ME_API + 'h5/h5EditExperience',
				type: 'post',
				data: data,
				success: function (res) {
					if (res.code == 2) {
						mui.toast('修改成功!');
						setTimeout(function () {
							window.history.back()
						}, 1000)
					} else {
						mui.toast(res.msg)
					}
				}
			})
		})
	</script>

</body>

</html>